package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: lei
 * @Date 2021/11/25 15:01
 **/
@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;

    //供应商信息分页展示
    @Override
    public Map<String, Object> list(String page, String rows, String supplierName) {

        List<Supplier> list = supplierDao.list(Integer.parseInt(page), Integer.parseInt(rows), supplierName);
        Map<String,Object> map = new HashMap<>();
        map.put("total",list.size());
        map.put("rows",list);
        return map;
    }

     // 保存或更新供应商

    @Override
    public void saveOrUpdate(Supplier supplier) {
        if (supplier.getSupplierId()!=null){
            supplierDao.update(supplier);
        }else{
            supplierDao.save(supplier);
        }

    }

    // 删除
    @Override
    public void delete(String ids) {
        String[] split = ids.split(",");
        supplierDao.delete(split);
    }
}
